<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      // 使用for循环封装还原filter函数

      Array.prototype.myFilter = function (callback) {
        // console.log(this)
        // console.log(callback)
        let newArr = []
        for (let i = 0; i < arr.length; i++) {
          if (callback(this[i], i, this)) {
            newArr.push(this[i])
          }
        }
        return newArr
      }

      let arr = [1, 3, 5, 7, 8, 9, 11]
      let obj = arr.myFilter(function (item, index, array) {
        // console.log(item)
        if (item % 2 === 0) {
          return item
        }
      })
      console.log(obj)
    </script>
  </body>
</html>
